SIFT algorithm¶

In this code I try to test SIFT for normal panorama images and scaled,rotated and intensity changed images

In [ ]:
import numpy as np
import matplotlib.pyplot as plt
import cv2
import random
import imutils
import SIFT_HM5 

Normal image


We can see shade of images but SIFT do it well

I decide to use belending mode for remove this shade in algorithm

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")
    
    # The stitch object to stitch the image
    blending_mode = "noBlending" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Normal image with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img+blending")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Croped image (different size) with blending mode¶

In [ ]:
fileNameList = [('1000', '1001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img+belnding")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Croped image (different size) with blending mode¶

In [ ]:
fileNameList = [('2000', '2001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data//"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")
    
    # The stitch object to stitch the image
    blending_mode = "noBlending" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img+blending")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Rotated image (90) with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")

    img_right = imutils.rotate(img_right, 90)
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_90 rotate")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Rotated image (180) with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")

    img_right = imutils.rotate(img_right, 180)
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_180_rotate")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Rotated image (45) with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")

    img_right = imutils.rotate_bound(img_right, 45)
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_45_rotate")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Rotated image (135) with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")

    img_right = imutils.rotate_bound(img_right, 135)
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_135_rotate")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Scaled image with blending mode¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")


    scale_percent = 80
    width = int(img_right.shape[1] * scale_percent / 100)
    height = int(img_right.shape[0] * scale_percent / 100)
    dsize = (width, height)
    img_right = cv2.resize(img_right, dsize)

   
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_scaled+blending")
    plt.imshow(warp_img[:,:,::-1].astype(int))

Blending mode with change intensity of right image¶

In [ ]:
fileNameList = [('0000', '0001')]
for fname1, fname2 in fileNameList:
    # Read the img file
    src_path = "img/data/"
    fileName1 = fname1
    fileName2 = fname2
    img_left = cv2.imread(src_path + fileName1 + ".jpg")
    img_right = cv2.imread(src_path + fileName2 + ".jpg")


    img_right=cv2.convertScaleAbs(img_right, 1.3, 1.3)
    
    # The stitch object to stitch the image
    blending_mode = "linearBlendingWithConstant" # three mode - noBlending、linearBlending、linearBlendingWithConstant
    warp_img = SIFT_HM5.stitch([img_left, img_right], blending_mode)

    # plot the stitched image
    plt.figure(13)
    plt.title("warp_img_intensity+blending")
    plt.imshow(warp_img[:,:,::-1].astype(int))